
!  --------------------------------------------------
!  Silverfrost FTN95 for Microsoft Visual Studio
!  Free Format FTN95 Source File
!  --------------------------------------------------

!program CallSecant
!implicit none
!implicit none
!real*8 epsilon, answer, x1, x2
!integer*2 count
!parameter (epsilon = 1.E-5)
!parameter (x1=2*1.E-3)
!parameter (x2=999*1.E-3)
!call secant (epsilon,x1,x2,answer,count)
!print*,answer
!print*,count
!pause
!end

subroutine secant (eps,a,b,hasil,count)
real*8 eps,a,b,hasil,f,c,tempa,tempb
integer*2 count
tempa = a
tempb = b
count = 0
do while (.true.)
    count = count + 1
    if (abs (f(tempa) - f(tempb)) < eps) then
        count = -1
        exit
    end if
    c = ((f(tempa)*tempb) - (f(tempb) *tempa)) / (f(tempa)-f(tempb))
    if (abs (c) < eps .or. abs (c-tempb) < eps) then
        hasil = c
        exit
    end if
    tempa = tempb
    tempb = c
end do
end


!real*8 function f(x)
!implicit none
!real*8 x
!f = -2. + (20 * x**2 + 1) / (1 + x**2)**2
!f = ((x*((2.1-(0.5*x))**0.5)) / ((1-x)*((1.1-(0.5*x))**0.5))) - 3.69
!end